package com.company.planner.entity;

import com.haulmont.chile.core.annotations.NamePattern;
import com.haulmont.cuba.core.entity.StandardEntity;
import com.haulmont.cuba.core.entity.annotation.OnDelete;
import com.haulmont.cuba.core.global.DeletePolicy;

import javax.persistence.*;
import java.util.List;

@Table(name = "PLANNER_INDEXS")
@Entity(name = "planner_Indexs")
@NamePattern("%s|indexName")
public class Indexs extends StandardEntity {
    private static final long serialVersionUID = -6208143992481401200L;

    @Column(name = "INDEX_ID")
    private String indexId;

    @Column(name = "INDEX_NAME")
    private String indexName;

    @Column(name = "MAPPINGS", length = 2000)
    private String mappings;

    @Column(name = "STATE")
    private String state;

    @JoinTable(name = "PLANNER_INDEXS_CLUSTER_LINK",
            joinColumns = @JoinColumn(name = "INDEXS_ID"),
            inverseJoinColumns = @JoinColumn(name = "ES_CLUSTER_CONFIG_ID"))
    @ManyToMany
    private List<EsClusterConfig> esClusterConfigs;

    @OnDelete(DeletePolicy.CASCADE)
    @OneToMany(mappedBy = "indexs")
    private List<Mappings> mappingList;

    @OnDelete(DeletePolicy.CASCADE)
    @OneToMany(mappedBy = "indexs")
    private List<IkAnalysisRule> ikAnalysisRules;

    public List<IkAnalysisRule> getIkAnalysisRules() {
        return ikAnalysisRules;
    }

    public void setIkAnalysisRules(List<IkAnalysisRule> ikAnalysisRules) {
        this.ikAnalysisRules = ikAnalysisRules;
    }

    public List<Mappings> getMappingList() {
        return mappingList;
    }

    public void setMappingList(List<Mappings> mappingList) {
        this.mappingList = mappingList;
    }

    public List<EsClusterConfig> getEsClusterConfigs() {
        return esClusterConfigs;
    }

    public void setEsClusterConfigs(List<EsClusterConfig> esClusterConfigs) {
        this.esClusterConfigs = esClusterConfigs;
    }

    public IndexState getState() {
        return state == null ? null : IndexState.fromId(state);
    }

    public void setState(IndexState state) {
        this.state = state == null ? null : state.getId();
    }

    public String getMappings() {
        return mappings;
    }

    public void setMappings(String mappings) {
        this.mappings = mappings;
    }

    public String getIndexName() {
        return indexName;
    }

    public void setIndexName(String indexName) {
        this.indexName = indexName;
    }

    public String getIndexId() {
        return indexId;
    }

    public void setIndexId(String indexId) {
        this.indexId = indexId;
    }
}